﻿using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
// --- Copyright (c) notice NevoWeb ---
//  Copyright (c) 2008 SARL NevoWeb.  www.nevoweb.com. BSD License.
// Author: D.C.Lee
// ------------------------------------------------------------------------
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// ------------------------------------------------------------------------
// This copyright notice may NOT be removed, obscured or modified without written consent from the author.
// --- End copyright notice --- 



using System.Runtime.Remoting;
using NEvoWeb.Modules.NB_Store.SharedFunctions;

namespace NEvoWeb.Modules.NB_Store
{

    public abstract class GatewayInterface
    {

        #region "Shared/Static Methods"

        // singleton reference to the instantiated object 
        private static GatewayInterface objProvider = null;

        private static Hashtable objArray = new Hashtable();
        // constructor
        static GatewayInterface()
        {
        }

        // dynamically create provider
        private static void CreateProvider(int PortalID, string ProviderAssembly, string ProviderClass)
        {
            ObjectHandle handle = null;

            if (string.IsNullOrEmpty(ProviderAssembly))
            {
                string[] Prov = null;
                Prov = Strings.Split(GetStoreSetting(PortalID, "gateway.provider", "XX"), ",");
                ProviderAssembly = Prov[0];
                ProviderClass = Prov[1];
            }

            handle = Activator.CreateInstance(ProviderAssembly, ProviderClass);
            objProvider = (GatewayInterface)handle.Unwrap();
            objArray.Add(PortalID.ToString() + ProviderAssembly, objProvider);

        }

        // return the provider
        public static new GatewayInterface Instance()
        {
            return Instance("", "");
        }

        public static new GatewayInterface Instance(string ProviderAssembly, string ProviderClass)
        {
            int PortalID = 0;
            PortalID = ((DotNetNuke.Entities.Portals.PortalSettings)HttpContext.Current.Items("PortalSettings")).PortalId;
            if (!objArray.ContainsKey(PortalID.ToString() + ProviderAssembly))
            {
                CreateProvider(PortalID, ProviderAssembly, ProviderClass);
            }
            return (GatewayInterface)objArray[PortalID.ToString() + ProviderAssembly];
        }

        #endregion

        public abstract string GetButtonHtml(int PortalID, int OrderID, string Lang);

        public abstract void AutoResponse(int PortalID, System.Web.HttpRequest Request);

        public abstract string GetCompletedHtml(int PortalID, int UserID, System.Web.HttpRequest Request);

        public abstract bool GetBankClick(int PortalID, System.Web.HttpRequest Request);

        public abstract void SetBankRemotePost(int PortalID, int OrderID, string Lang, System.Web.HttpRequest Request);

    }

}